//
//  MapSearchListView.m
//  Cycling
//
//  Created by 迟国强 on 2023/3/26.
//

#import "MapSearchListView.h"
#import "MapSearchListCell.h"
#import "MapRequest.h"

@implementation MapSearchListView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [MapRequest searchRecordWithResult:^(NSDictionary * _Nonnull dic) {
            
        }];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    self.backgroundColor = UIColor.whiteColor;
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, SafeAreaTopHeight, 50, 44);
    [btn setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateHighlighted];
    btn.ce_size = CGSizeMake(50, 44);
    [btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self addSubview:btn];
    
    UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(70, SafeAreaTopHeight + 10, SCREEN_W - 90, 30)];
    whiteView.backgroundColor = [UIColor whiteColor];
    whiteView.layer.borderColor = rgb(238, 238, 238).CGColor;
    whiteView.layer.borderWidth = 1;
//    [whiteView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)]];
    [self addSubview:whiteView];
    
    UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(10, 7.5, 15, 15)];
    iv.image = [UIImage imageNamed:@"sousuo"];
    [whiteView addSubview:iv];
    
    UITextField *searchF = [[UITextField alloc] initWithFrame:CGRectMake(31, 0, whiteView.ce_width - iv.right - 16, 26)];
    searchF.placeholder = @"搜索";
    searchF.textColor = rgb(176, 176, 176);
    searchF.font = [UIFont systemFontOfSize:16];
    [whiteView addSubview:searchF];
    whiteView.layer.cornerRadius = 4;
    whiteView.layer.masksToBounds = YES;
    
    self.tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 50 + SafeAreaTopHeight, SCREEN_W, self.ce_height - SafeAreaBottomHeight - 110 - SafeAreaTopHeight) style:UITableViewStylePlain];
    [self addSubview:self.tableView];
    self.tableView.backgroundColor=[UIColor clearColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.showsHorizontalScrollIndicator = NO;
    [self.tableView registerNib:[UINib nibWithNibName:@"MapSearchListCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MapSearchListCell"];
    
}

- (void)back {
    self.removeFromSuperview;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 20;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MapSearchListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MapSearchListCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"MapSearchListCell" owner:self options:nil] lastObject];
    }
    return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    MJVIPDetailViewController *vc = [[MJVIPDetailViewController alloc] init];
//    [self.navigationController pushViewController:vc animated:YES];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

@end
